var app = getApp();
Page(Object.assign({}, {
    data:{
        page : {
            isend : false,
            doing : false,
            doo : 'user_v1',
            pdata : {
                op : 'mymoney',
                page : 1,
                status : 0,
            },
            waitf : 0,
            nodataf : 0,
        },
        datalist : [],
        inited : false,
        form : {},
        userinfo : {},
		siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
        isshowzz : false,
        money : '',
        tarid : '',
        uid : '',
        nickname : '',
        isshowlist : '',
    },
    onLoad:function(options){
        var self = this;
        app.com.auth(function(user){
            app.com.getPage(self,self.data.page,0,function(res){
                var data = res.data.data;
                self.setData({
                   datalist : data.list,
                   params : res.data.data.params,
                   sharedata : res.data.data.sharedata,
                   userinfo : res.data.data.userinfo,
                },function(){
                    self.setData({
                        inited : true,
                    });
                });

                wx.setNavigationBarTitle({
                  title:  res.data.data.params.umname ? res.data.data.params.umname : '余额',
                });

            },false,function(res){
                app.com.alert(res.data.message);
            });
        });
    },
    onShareAppMessage : function(){
        var self = this;
        return {
            title: self.data.params.umname,
            path: '',
        }
    },
    onPullDownRefresh: function () {
        this.setData({
            'page.pdata.page' : 1,
            'page.waitf' : 0,
            'page.nodataf' : 0,
            'page.isend' : false,
        })
        this.onLoad();
        wx.stopPullDownRefresh();
    },
    onReachBottom : function(){
        var self = this;
        app.com.getPage(self,self.data.page,0,function(res){
            self.setData({
                datalist : self.data.datalist.concat(res.data.data.list)
            });
        });
    },
    showzz(){
        this.setData({
            isshowzz : !this.data.isshowzz,
        })
    },
    confirmto(){
        var self = this;
        var postdata = {
            op : 'moneytouser',
            uid : self.data.uid,
            money : self.data.money,
        };
        app.com.confirm('确定转账支出吗？',function(){
            app.com.http('user_v1','POST',postdata,0,true,'','',function(res){
                if (res.data && !res.data.errno) {
                    app.com.alert(res.data.message);
                    self.setData({
                        'userinfo.umoney' : res.data.data.umoney,
                        isshowzz : false,
                        money : '',
                    })
                }else{
                    app.com.alert( res.data.message );
                }
            });
        });
    },
    searchuser(){
        var self = this;
        var postdata = {
            op : 'searchuser',
            tarid : self.data.tarid,
        };
        app.com.http('user_v1','POST',postdata,0,true,'','',function(res){
            if (res.data && !res.data.errno) {
                app.com.toast(res.data.message);
                self.setData({
                    userlist : res.data.data,
                    isshowlist : true,
                })
            }else{
                app.com.toast( res.data.message );
            }
        });
    },
    changeinput(e){
        var name = e.currentTarget.dataset.name;
        var value = e.detail.value;
        this.setData({
            [name] : value
        })
    },
    showlist(){
        this.setData({
            isshowlist : !this.data.isshowlist
        })
    },
    selectu(e){
        var i = e.currentTarget.dataset.i;
        this.setData({
            uid : this.data.userlist[i].id,
            nickname : this.data.userlist[i].nickname,
            isshowlist : false,
        })
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e,this.data.tid );
    },
    redirectto : function( e ){
        app.com.redirectto( e,this.data.tid );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    }
}))